<?php
// .-----------------------------------------------------------------------------------
// | WE TRY THE BEST WAY 杭州博也网络科技有限公司
// |-----------------------------------------------------------------------------------
// | Author: 青 <99701759@qq.com>
// | Copyright (c) 2013-2016, http://www.itboye.com. All Rights Reserved.
// |-----------------------------------------------------------------------------------
// 微信用户表中的信息在$this->userinfo
// 用户newmember表的信息在$this->newmember中
// 用户角色表的信息在$this->role中
namespace app\web\controller;

use app\src\activity\logic\ActivityLogic;
use app\src\activity\logic\UserActivityLogic;
use app\src\system\logic\DatatreeLogicV2;
use app\src\user\logic\MemberLogic;
class Activity extends Base{




    /*
     * 首页
     * */
    public function index(){

//        $parent='6235';
//
//        $map['parents'] = array('like','%'.$parent.',%');
//        $result=(new DatatreeLogicV2())->queryNoPaging($map);
//        $list = \app\src\admin\helper\MenuHelper::list_to_tree($result,'id','parentid','_child',$parent);
//       // dump($list);exit;
//
//        $this->assign('list',$list);
//
//      //  dump('aa');
        return $this->fetch();
    }



    public function data()
    {

        $params = array();
        $map = array();
        $page = array('curpage' => $this->_param('p', 0), 'size' => 5);
        $order = "create_time desc ";
      //  $map['dtree_type'] = $this->_param('type');
        $map['act_status'] = 0;
        //     dump($map);
        $result = (new ActivityLogic())->queryCacheWithPagingHtml($map, $page, $order, $params);
//dump($result);

        $data=array();
        if ($result['status']&&!empty($result['info']['list'])) {
            foreach ($result['info']['list'] as $k => $v) {
                $data[$k]['id'] = $v['id'];
                $data[$k]['title'] = $v['title'];
                $data[$k]['img'] = $v['img'];
                $data[$k]['start_time']=$v['create_time'];
            }
            $data = json_encode($data);
            echo $data;
        }else{
            $data = json_encode($data);
            echo $data;
        }

    }

    /*
     * 活动详情
     * */
    public function detail(){

        $act_id=$this->_param('id');
      //  $order='itboye_product.create_time desc';
        $result = (new ActivityLogic())->getCacheInfo(['id'=>$act_id]);
        $detail=$result['info']['content'];

        $this->assign('act_id',$act_id);
            $this->assign('detail',$detail);

        return $this->fetch();
        }

    public function mydetail(){

        $act_id=$this->_param('id');
        //  $order='itboye_product.create_time desc';
        $result = (new ActivityLogic())->getCacheInfo(['id'=>$act_id]);
        $detail=$result['info']['content'];

        $this->assign('act_id',$act_id);
        $this->assign('detail',$detail);

        return $this->fetch();
    }
    public function registration(){

        $uid   = $this->memberinfo['id'];
        $act_id=$this->_param('act_id');
        $name=$this->_param('name');
        $tel=$this->_param('tel');
        $isreg = (new UserActivityLogic())->getInfo(['uid'=>$uid,'act_id'=>$act_id]);
        if($isreg['status']&&!empty($isreg['info'])){
            $this->error('已经报名过，不要重复报名');
        }
        $entity=array(
            'act_id'=>$act_id,
            'uid'=>$uid,
            'name'=>$name,
            'tel'=>$tel,
            'status'=>0
        );
//dump($entity);exit;
        $result = (new UserActivityLogic())->add($entity);
        if($result['status']) {
            $this->success('报名成功', url('index/index'));
        }else{
            $this->error('报名失败');
        }
        return $this->fetch();
    }

    public function ajaxReturn($data){
        //不做处理
    }


}